package com.example.discover_model;

import com.blankj.utilcode.util.SPUtils;
import com.example.common.filed.DataActionEntity;
import com.example.common.mvvm.viewmodel.BaseViewModel;
import com.example.discover_model.entity.FindListEntity;
import com.example.network_skd.BaseEntity;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class FindViewModel extends BaseViewModel<FindRepository> {
    @Override
    protected void initData() {
        repository.requestFindList(0, 10, "all", 0, SPUtils.getInstance().getLong("userId"))
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }

    @Override
    protected void onResult(BaseEntity baseEntity) {
        if (baseEntity instanceof FindListEntity){
            FindListEntity findListEntity  = (FindListEntity) baseEntity;

            DataActionEntity dataActionEntity = new DataActionEntity();
            dataActionEntity.action="DATA";
            Map<String,Object> map = new HashMap<>();

            map.put("FINDDATA",findListEntity.data);
            dataActionEntity.data =map;
            vmData.post(dataActionEntity);
        }
    }
}
